#include "bsp_RingBuffer.h"

// uint8_t UART01_XXXX_BUF[64]; // 定义环型buff
RingBuffer_Typedef MB_RxBuf;

void RB_WriteByte(RingBuffer_Typedef *Rbuf, unsigned char data)
{
    Rbuf->RB_Data[Rbuf->RB_Index] = data;
    Rbuf->RB_Index++;

    if (Rbuf->RB_Index >= RB_FIFO_MAX_SIZE)
    {
        Rbuf->RB_Index = 0;
    }
}

unsigned char RB_ReadBytes(RingBuffer_Typedef *Rbuf, unsigned char *data, unsigned char Datalen)
{
    for (unsigned char i = 0; i < Datalen; i++)
    {
        if (Rbuf->RB_Index != Rbuf->RB_Outdex)
        {
            data[i] = Rbuf->RB_Data[Rbuf->RB_Outdex];
        }
        else
        {
            return i;
        }

        Rbuf->RB_Outdex++;

        if (Rbuf->RB_Outdex >= RB_FIFO_MAX_SIZE)
        {
            Rbuf->RB_Outdex = 0;
        }
    }

    return Datalen;
}
